<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright © 2002 - 2011 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: server_status_panel.php
| CVS Version: 2.00
| Author: ShadowMage
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
if (!defined("IN_FUSION_SECURE")) { die("Access Denied"); }

include INFUSIONS."server_status_panel/server_status_db.php";

// Check if locale file is available matching the current site locale setting.
if (file_exists(INFUSIONS."server_status_panel/locale/".$settings['locale'].".php")) {
	// Load the locale file matching the current site locale setting.
	include INFUSIONS."server_status_panel/locale/".$settings['locale'].".php";
} else {
	// Load the infusion's default locale file.
	include INFUSIONS."server_status_panel/locale/English.php";
}

openside($locale['svi_title']);
$get_servers = dbquery("SELECT * FROM `".DB_SERVERS_TABLE."` WHERE `use_panel` = '1';");
if(dbrows($get_servers) == 0)
{
    print $locale['svi_no_servers_using_panel'];
}else{
    while($server = dbarray($get_servers))
    {
        print "<table>
        <tr>
        <th align=\"center\" valign=\"middle\">
            $server[server_name]
        </th>
        </tr>\n";
        $get_services = dbquery("SELECT * FROM `".DB_SERVICES_TABLE."` WHERE `server_id` = '$server[server_id]' AND `service_use_panel` = '1';");
        while($service = dbarray($get_services))
        {
            $check_service = @fsockopen($server['server_name'],$service['service_port'],$errno,$errstr,2);
            $svc_stats = ($check_service) ? 'tick' : 'cross';
            print "<tr>
            <td align=\"left\" valign=\"middle\">
                $service[service_name]
            </td>
            <td align=\"right\" valign=\"middle\">
                <img src=\"".INFUSIONS."server_status_panel/images/$svc_stats.png\" alt=\"Service Status\" />
            </td>
            </tr>\n";
        }
        print "</table>";
    }
}
closeside();
?>
